package com.slkj.shilixiaoyuanapp.view;

import android.content.Context;
import android.graphics.Color;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.slkj.shilixiaoyuanapp.entity.BasePickerTypeEntity;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created  on 2018-07-19
 * @author 唐开阔
 * @describe 统一选择器出处，方便统一修改
 */
public class PickerViewProvider {

    /**
     * 时间选择器-精确到分
     * @param context
     * @param listener
     * @return
     */
    public static TimePickerView getTimePicker(Context context,OnTimeSelectListener listener){
       return new TimePickerBuilder(context, listener)
               .setDividerColor(Color.parseColor("#0087FC"))
               .setCancelColor(Color.parseColor("#999999"))
               .setType(new boolean[]{true, true, true, true, true, false}).build();
    }

    /**
     * 获取当前时间之后的时间
     * @param context
     * @param listener
     * @return
     */
    public static TimePickerView getAfterTimePicker(Context context,OnTimeSelectListener listener){
        Calendar calendar =  Calendar.getInstance();
        calendar.setTime(new Date());
        return new TimePickerBuilder(context, listener)
                .setRangDate(calendar, null)
                .setDividerColor(Color.parseColor("#0087FC"))
                .setCancelColor(Color.parseColor("#999999"))
                .setType(new boolean[]{true, true, true, true, true, false}).build();
    }



    public static TimePickerView getDayTimePicker(Context context,OnTimeSelectListener listener){
        return new TimePickerBuilder(context, listener)
                .setType(new boolean[]{true, true, true, false, false, false})
                .setDividerColor(Color.parseColor("#0087FC"))
                .setCancelColor(Color.parseColor("#999999"))
                .build();
    }
    public static TimePickerView getDayTimePickerBefor(Context context,OnTimeSelectListener listener,Date date){
        Calendar calendar = null;
        if (date != null){
             calendar =  Calendar.getInstance();
            calendar.setTime(date);
            calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)-1);

        }
        return new TimePickerBuilder(context, listener)
                .setRangDate(null, calendar)
                .setType(new boolean[]{true, true, true, false, false, false})
                .setDividerColor(Color.parseColor("#0087FC"))
                .setCancelColor(Color.parseColor("#999999"))
                .build();
    }
    public static TimePickerView getDayTimePickerAfter(Context context,OnTimeSelectListener listener,Date date){
        Calendar calendar = null;;
        if (date != null){
            calendar =  Calendar.getInstance();
            calendar.setTime(date);
            calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)+1);
        }
        return new TimePickerBuilder(context, listener)
                .setRangDate(calendar, null)
                .setType(new boolean[]{true, true, true, false, false, false})
                .setDividerColor(Color.parseColor("#0087FC"))
                .setCancelColor(Color.parseColor("#999999"))
                .build();
    }
    public static TimePickerView getDayTimePickerBefor(Context context,OnTimeSelectListener listener,boolean[] booleans,Date date){
        Calendar calendar = null;
        if (date != null){
            calendar =  Calendar.getInstance();
            calendar.setTime(date);
            calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)-1);

        }
        return new TimePickerBuilder(context, listener)
                .setDividerColor(Color.parseColor("#0087FC"))
                .setCancelColor(Color.parseColor("#999999"))
                .setType(booleans).build();
    }
    /**
     * 时间选择器-精确到分
     * @param context
     * @param listener
     * @return
     */
    public static TimePickerView getTimePicker(Context context,OnTimeSelectListener listener,boolean[] booleans){
        return new TimePickerBuilder(context, listener)
                .setDividerColor(Color.parseColor("#0087FC"))
                .setCancelColor(Color.parseColor("#999999"))
                .setType(booleans).build();
    }


    /**
     * 选择科目
     * @param context
     * @param workKmEntities
     * @param listener
     * @return
     */
    public static OptionsPickerView getCommonPicker(Context context, List workKmEntities, OnOptionsSelectListener listener){
        OptionsPickerView pvNoLinkOptions = new OptionsPickerBuilder(context, listener)
                .setCancelColor(Color.parseColor("#999999")).build();
        pvNoLinkOptions.setPicker(workKmEntities);
        return pvNoLinkOptions;
    }

    /**
     * 作业类型
     * @param context
     * @param workKmEntities
     * @param listener
     * @return
     */
    public static OptionsPickerView getWorkTypePicker(Context context, List<BasePickerTypeEntity> workKmEntities, OnOptionsSelectListener listener){
        OptionsPickerView pvNoLinkOptions = new OptionsPickerBuilder(context, listener)
                .setCancelColor(Color.parseColor("#999999")).build();
        pvNoLinkOptions.setPicker(workKmEntities);
        return pvNoLinkOptions;
    }

    /**
     * 获奖类别
     *
     *
     * */
    public static OptionsPickerView getWinTypePicker(Context context,List<BasePickerTypeEntity> workKmEntities1,List<List<BasePickerTypeEntity>> workKmEntities2,OnOptionsSelectListener listener){
        OptionsPickerView pickerView=new OptionsPickerBuilder(context,listener)
                .setCancelColor(Color.parseColor("#999999")).build();
        pickerView.setPicker(workKmEntities1,workKmEntities2);
        return pickerView;
    }
}
